# -*- coding: UTF-8 -*-
#coding=utf-8
#fileAllName是文件的全名，strReplaceMap为关联数组
#key表示被替换的字符，value为替换为的变量
def AlterFileStrReplace(fileAllName,strReplaceMap):
    f1=None;
    f2=None;
    file_data = ""
    #f1 = open(fileAllName, "r")
    try:
        f1 = open(fileAllName, "r")
        while 1:
            line = f1.readline()
            if not line:
                break
            for key in strReplaceMap:
                if key in line:
                    line = line.replace(key, strReplaceMap[key])
            file_data += line
        file_data = file_data.decode('utf-8')
        f2 = open(fileAllName, "w")
        f2.write(file_data)
    except Exception as err:
        print(err)
    finally:
        if(f1!=None):
            f1.close()
        if(f2!=None):
            f2.close()